#define _CRT_SECURE_NO_WARNINGS 1 
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <stack>
using namespace std;


class Solution {
public:
	vector<int> sortedSquares(vector<int>& nums) {
		int numStart = 0;
		int numEnd = nums.size() - 1;
		vector<int> result(nums.size(), 0);
		int k = nums.size() -1;
		while (numEnd >= numStart)
		{
			if (nums[numStart] * nums[numStart] > nums[numEnd] * nums[numEnd])
			{
				result[k--] = nums[numStart] * nums[numStart];
				numStart++;
			}
			else
			{
				result[k--] = nums[numEnd] * nums[numEnd];
				numEnd--;
			}	
		}
		return result;
	}
};


int main()
{
	vector<int> arr_int = { -10, -4, -3, 0, 3, 7 };
	Solution st;
	vector<int> reuslt =  st.sortedSquares(arr_int);

	system("pause");
	return 0;
}